package com.nan.buy.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.nan.buy.model.Admin;
import com.nan.buy.service.AdminService;

@Controller
@RequestMapping("administrator")
public class AdminController {

	@Resource
	private AdminService adminService;
	
	@RequestMapping("administrator")
	public String administrator(){
		return "admin/adminList";
	}
	
	/*
	 * 查詢所有管理員信息
	 */
	@RequestMapping("search")
	@ResponseBody
	public List<Admin> searchAdmins(){
		return adminService.searchAdmins();
		
	}
	
	/*
	 * 按用戶名搜索
	 */
	@RequestMapping("searchByName")
	@ResponseBody
	public List<Admin> searchByName(String aName){
		return adminService.searchByName(aName);
	}
	
	
	/*
	 * 修改
	 */
	@RequestMapping("update")
	@ResponseBody
	public Object updateAdmin(Admin admin){
		int msg=adminService.updateAdmin(admin);
		return (msg != 0) ? true : false;
	}
	
	/*
	 * 刪除
	 */
	@RequestMapping("del")
	@ResponseBody
	public Object delAdmin(String aId){
		int msg=adminService.delAdmin(aId);
		return (msg != 0) ? true : false;
	}
	
	/*
	 * 添加
	 */
	@RequestMapping("add")
	@ResponseBody
	public Object addAdmin(Admin admin){
		int msg=adminService.addAdmin(admin);
		return (msg != 0) ? true : false;
	}
}
